export function didMount() {
    const self = this;

    // 轮询获取按钮，确保元素加载完成
    const interval = setInterval(() => {
        let btn = self.$$("import_data_4w5hv5");
        if (!btn) return;

        clearInterval(interval); // 找到按钮后停止轮询
        console.log("按钮已找到:", btn);

        let btnEle = btn.$el;
        btnEle.addEventListener("click", function () {
            console.log("Button was clicked!");
            const modal = document.querySelector("#u-import-data-modal");

            if (!modal) {
                console.warn("模态框未找到");
                return;
            }

            // 监听弹窗打开和关闭
            const observer = new MutationObserver((mutationsList) => {
                for (let mutation of mutationsList) {
                    if (mutation.attributeName === "style") {
                        if (modal.style.display !== "none") {
                            console.log("弹窗已打开！");
                        } else {
                            console.log("弹窗已关闭，获取参数...");
                            observer.disconnect(); // 监听到关闭后，取消监听
                            doPostAction();
                        }
                    }
                }
            });

            observer.observe(modal, {attributes: true});

            console.log("监听弹窗状态变化...");
        });
    }, 100);
}

// 关闭弹窗后的后置操作
function doPostAction() {
    console.log("弹窗关闭后，获取参数...");

    // 3. 获取隐藏的 data-* 属性
    const hiddenData = document.querySelector("#u-import-data-modal")?.dataset;

    // 4. Vue 组件中的数据
    const vueComponent = document.querySelector("#u-import-data-modal")?.__vue__;
    const modalData = vueComponent ? vueComponent.yourVueData : null;


    // 这里可以做后续处理，比如发请求
}
